package com.yanqu.road.server.cmd.manor;

import com.yanqu.road.pb.manor.ManorProto;
import com.yanqu.road.server.cmd.base.AbstractCommand;
import com.yanqu.road.server.command.Cmd;
import com.yanqu.road.server.gameplayer.GamePlayer;
import com.yanqu.road.server.gameplayer.module.manor.ManorModule;
import com.yanqu.road.message.YanQuMessage;
import com.yanqu.road.server.protocol.ClientProtocol;
import com.yanqu.road.server.protocol.GameProtocol;

/**
 * @author ：zfr
 * @date ：2021/5/21 10:52
 */
@Cmd(code = GameProtocol.S_MANOR_OBJECT_SPECIAL_SKILL_LV_UP, desc = "庄园物件附加技能升级")
public class ManorObjectSpecialSkillLvUpCmd extends AbstractCommand {
    private int id;
    private boolean together;

    @Override
    public boolean parseData(YanQuMessage packet) throws Exception {
        ManorProto.ManorSpecialSkillLevelUpReqMsg msg = ManorProto.ManorSpecialSkillLevelUpReqMsg.parseFrom(packet.getBytes());
        id = msg.getId();
        together = msg.getTogether();
        return true;
    }

    @Override
    public void execute(GamePlayer player, YanQuMessage packet) throws Exception {
        if (!together) {
            ret = player.getModule(ManorModule.class).specialSkillLevelUp(id);
        }else {
            ret = player.getModule(ManorModule.class).specialSkillLevelUpTogether(id);
        }

    }

    @Override
    public void sendData(GamePlayer player) {
        if (!together || ret > 0) {
            ManorProto.ManorSpecialSkillLevelUpRespMsg.Builder respMsg = ManorProto.ManorSpecialSkillLevelUpRespMsg.newBuilder();
            respMsg.setRet(ret);
            player.sendPacket(ClientProtocol.U_MANOR_OBJECT_SPECIAL_SKILL_LV_UP, respMsg);
        }
    }
}
